package org.jdpf.gui.rcp.neteditor.core.blocks;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.jdpf.core.kernel.plugins.IPluginsFrameworkConstants;
import org.jdpf.gui.rcp.neteditor.core.elements.GraphicNet;
import org.osgi.framework.Bundle;

public class GTransformer extends AbstractGraphicBlock {

	public GTransformer(Bundle bundle, GraphicNet gnet) {
		super(bundle, gnet);
		category = IPluginsFrameworkConstants.TRANSFORMER;
		height = 30;
		width = 60;
		int connectorLength = 40;
		
		addInputPosition(new Point( (-1)*connectorLength, 15));
		addOutputPosition(new Point(width+connectorLength, 15));
		setTransitionName("Trasformer transition");
	}

	public void draw(GC gc) {
		super.draw(gc);
		
		int delta=5;
		int border=1;
		Color black = gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
		gc.setBackground(black);
		
		gc.fillPolygon(new int[]{
				position.x, position.y,
				position.x, position.y + height,
				position.x+(width/2), position.y + height - delta,
				position.x+width, position.y+height,
				position.x+width, position.y,
				position.x+(width/2), position.y + delta
		});
		
		gc.setBackground(statusColor);
		
		gc.fillPolygon(new int[]{
				position.x+border, position.y+border,
				position.x+border, position.y + height-border,
				position.x+(width/2), position.y + height - delta-border,
				position.x+width-border, position.y+height-border,
				position.x+width-border, position.y+border,
				position.x+(width/2), position.y + delta+border
		});		
		
		gc.setForeground(black);
		gc.drawLine(position.x+(width/2), position.y+delta+border,
				position.x+(width/2), position.y+height-delta-border);
		
		drawInputConnectors(gc);
		drawOutputConnectors(gc);
	}

}
